package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface UserMapper {
    /**
     * 根据openid查询用户
     *
     * @param openid
     * @return
     */
    @Select("select *from user where openid=#{openid}")
    User getByOpenid(String openid);

    /**
     * 插入注册新用户
     *
     * @param user
     */
    void insert(User user);

    @Select("select * from user where id=#{userId}")
    User getById(Long userId);

    /**
     * 区间段查询用户新增数据
     *
     * @param map
     * @return
     */
    Integer sumUserIdByMap(Map map);

    /**
     * 查询用户个数
     * 采用userId来进行区分不同的用户
     *
     * @param map
     * @return
     */
    @Select("select count(distinct orders.user_id) from orders where order_time>=#{begin} and order_time<=#{end} and status=#{status}")
    Integer sumUserCountByMap(Map map);
}
